<?php

require_once 'common/common.inc.php';

$service_code = "CAR_WASH";
$location_code = isset($_REQUEST["location_code"]) ? $_REQUEST["location_code"] : null;
$_SESSION["LOCATION_CODE"] = $location_code;

$sql = "";
$sql .= "SELECT s.ID, s.START, DATE_FORMAT(s.START,'%Y-%m-%d') START_SHORT_ISO, ";
$sql .= "  ( SELECT COUNT(1) ";
$sql .= "    FROM SCHEDULES s1  ";
$sql .= "      INNER JOIN RESERVATIONS r1 ON s1.ID = r1.SCHEDULE_ID  ";
$sql .= "          AND s1.SERVICE_CODE = '$service_code'  ";
$sql .= "    WHERE DATE_FORMAT(s1.START,'%Y-%m-%d') = DATE_FORMAT(s.START,'%Y-%m-%d') ) RESERVATION_COUNT ";
$sql .= "FROM SCHEDULES s ";
$sql .= "WHERE s.LOCATION_CODE = '$location_code' ";
$sql .= "AND s.SERVICE_CODE = '$service_code' ";
//echo $sql;
conn();
$result = mysql_query($sql);
if (!$result) {die('Could not exec query: ' . mysql_error());}
$numRows = mysql_num_rows($result);
close();

$now = new DateTimeDutch();
$now->setTimezone($timezone); 

?>

<?php

if ($logged_in==false) {
  $error = "U dient zich eerst aan te melden.";
  echo '<p><span class="error">'.$error.'</span></p>';
  exit;
} else if ($numRows == 0) {
  ?>
    <p>
      <span class="error">
        Er zijn geen vooraf gereserveerde dagen voor jouw locatie gevonden.<br />
        Klik <a href="mailto:info@redjezaterdag.nl?subject=Aanvraag mogelijkheden auto stomen - <?php echo $location_code?>">hier</a>
        om de beschikbare data aan te vragen.
      </span>
    </p>
  <?php
  exit;
} 
?>

<script type="text/javascript">
var today = <?php echo "'".$now->format( 'Y-m-d' )."'"; ?>;
var days = new Array();
var rCount = new Array();
<?php
$counter = 0;
if ($logged_in==false) {
  $error = "U dient zich eerst aan te melden.";
} else if ($numRows > 0) {
  while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
      echo "days[$counter]='";
      echo $row["START_SHORT_ISO"];
      echo "';\n";
      
      echo "rCount['".$row["START_SHORT_ISO"]."']=";
      echo $row["RESERVATION_COUNT"];
      echo ";\n";
      
      $counter = $counter + 1;
  }
  mysql_data_seek($result, 0); 
} else {
  $error = "Er zijn geen beschikbare dagen gevonden.";
}
?>

$(function(){
  $('#datepicker_car_wash').datepicker({
        numberOfMonths: 1,
        inline: true,
        dateFormat: 'yy-mm-dd',
        altField: '#date_due',
        altFormat: 'yy-mm-dd',
        beforeShowDay: highlightDays,
        onSelect: pickDateAutoWassen,
        onChangeMonthYear: changeMonthYear,
        firstDay: 1 // rows starts on Monday
  });
})

</script>

<div class="title">
  Klik hieronder op een van de <span class="bg">beschikbare dagen</span>
</div>        

<div class="datepicker" id="datepicker_car_wash"></div>

